-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for list emptiness before checking variants #178
Conversation
fd80685
to
e34834f
Compare
Why? Filter of an empty list is already the empty list |
e34834f
to
403451c
Compare
sorry meant to do this in the |
Might be worth adding to the commit message the example failure that raised this
Which resulted from trying to build this change - MarkSymsCtx/xen-api@692d17d |
src/lib/pythongen.ml
Outdated
| variants_to_check -> | ||
List.fold_left | ||
(fun acc x -> List.concat [ acc; check false x ]) | ||
(check true (List.hd variants_to_check)) | ||
(List.tl variants_to_check) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| variants_to_check -> | |
List.fold_left | |
(fun acc x -> List.concat [ acc; check false x ]) | |
(check true (List.hd variants_to_check)) | |
(List.tl variants_to_check) | |
| v :: vs -> | |
List.fold_left | |
(fun acc x -> List.concat [ acc; check false x ]) | |
(check true v) vs |
You can simplify this further with pattern matching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be probably worth to add a test, so that there are no regressions when updating the code in the future
Signed-off-by: Vincent Liu <[email protected]>
403451c
to
6cacde3
Compare
(check true (List.hd variants_to_check)) | ||
(List.tl variants_to_check) | ||
match variants_to_check with | ||
| [] -> [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vincent-lau I think @mseri meant that you didn't need the | [] -> []
if you used | v :: vs ->
form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need both, the second one pattern matches only on nonempty lists
86dd0b3
to
21ccda9
Compare
unit tests written, should be good to go |
If the test requires the use of ppx, please move it to the |
In fact, could it not go into https://github.com/mirage/ocaml-rpc/blob/master/tests/ppx/variants.ml ? |
I think there is a |
This tests whether it can handle the case where a varaiant consist only of zero-arg constructors. Signed-off-by: Vincent Liu <[email protected]>
21ccda9
to
4f9b5d2
Compare
No description provided.